cmake_minimum_required(VERSION 3.22)
project(dir_test)

include_directories(testdir1)
message("--$ include_directories: testdir1")


# 获取当前文件的INCLUDE_DIRECTORIES目录属性
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
message("--$ in directory: ${CMAKE_CURRENT_SOURCE_DIR}, include dir list: ${dirs}")

# 编译testdir1下的库
add_subdirectory(testdir1)
message("--$ after compile lib test1")
get_property(dirs TARGET test1 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test1 include dir list: ${dirs}")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
message("--$ current file include dir list: ${dirs}")


# 编译testdir2下的库
add_subdirectory(testdir2)
message("--$ after compile lib test2")
get_property(dirs TARGET test1 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test1 include dir list: ${dirs}")
get_property(dirs TARGET test2 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test2 include dir list: ${dirs}")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
message("--$ current file include dir list: ${dirs}")


add_executable(main main.cpp)
message("--$ after add exe main")
get_property(dirs TARGET test1 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test1 include dir list: ${dirs}")
get_property(dirs TARGET test2 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test2 include dir list: ${dirs}")
get_property(dirs TARGET main PROPERTY INCLUDE_DIRECTORIES)
message("--$ executable main include dir list: ${dirs}")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
message("--$ current file include dir list: ${dirs}")
message("---")


target_link_libraries(main test1)
message("--$ after add lib test1")
get_property(dirs TARGET test1 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test1 include dir list: ${dirs}")
get_property(dirs TARGET test2 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test2 include dir list: ${dirs}")
get_property(dirs TARGET main PROPERTY INCLUDE_DIRECTORIES)
message("--$ executable main include dir list: ${dirs}")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
message("--$ current file include dir list: ${dirs}")
message("---")


target_link_libraries(main test2)
message("--$ after add lib test2")
get_property(dirs TARGET test1 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test1 include dir list: ${dirs}")
get_property(dirs TARGET test2 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test2 include dir list: ${dirs}")
get_property(dirs TARGET main PROPERTY INCLUDE_DIRECTORIES)
message("--$ executable main include dir list: ${dirs}")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
message("--$ current file include dir list: ${dirs}")
message("---")


include_directories(testdir2)
message("--$ include_directories: testdir2")
get_property(dirs TARGET test1 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test1 include dir list: ${dirs}")
get_property(dirs TARGET test2 PROPERTY INCLUDE_DIRECTORIES)
message("--$ lib test2 include dir list: ${dirs}")
get_property(dirs TARGET main PROPERTY INCLUDE_DIRECTORIES)
message("--$ executable main include dir list: ${dirs}")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
message("--$ current file include dir list: ${dirs}")
message("---")